package com.atXiao.food.rspbody;

import com.atXiao.food.rspcode.BaseResultCode;
import com.atXiao.food.rspcode.RspResultCode;
import java.io.Serializable;

/**
 * <吃啥啊>响应信息封装
 *
 * @author lixiaoxiao
 *
 * @date 2023-11-23
 */
public final class RspBody<T>  implements Serializable{

    /**
     * 返回码
     */
    private String retCode;

    /**
     * 返回描述
     */
    private String retDesc;

    /**
     * 返回数据
     */
    private T rspBody;

    /**
     * 成功
     *
     * @param resultCode 状态码枚举
     *
     * @param data     响应结果
     *
     * @param <T>
     *
     * @return ResBody
     */
    public static <T> RspBody ok(BaseResultCode resultCode, T data) {
        return new RspBody(resultCode.getCode(), resultCode.getDesc(), data);
    }

    /**
     * 成功
     *
     * @param data 响应结果
     * @param <T>
     * @return ResBody
     */
    public static <T> RspBody ok(T data) {
        return new RspBody(RspResultCode.REQUEST_SUCCESS, data);
    }


    /**
     * 失败
     *
     * @param resultCode 状态码枚举
     *
     * @param data     响应结果
     *
     * @param <T>
     *
     * @return ResBody
     */
    public static <T> RspBody fail(BaseResultCode resultCode, T data) {
        return new RspBody(resultCode.getCode(), resultCode.getDesc(), data);
    }

    /**
     * 失败
     *
     * @param data 响应结果
     * @param <T>
     * @return ResBody
     */
    public static <T> RspBody fail(T data) {
        return new RspBody(RspResultCode.SERVER_FAILURE, data);
    }

    public RspBody() {
    }

    /**
     * 统一响应
     *
     * @param retCode 状态码
     * @param retDesc 描述
     * @param rspBody 响应结果
     */
    public RspBody(String retCode, String retDesc, T rspBody) {
        this.retCode = retCode;
        this.retDesc = retDesc;
        this.rspBody = rspBody;
    }

    /**
     * 统一响应
     *
     * @param resultCode
     *
     * @param rspBody
     */
    public RspBody(BaseResultCode resultCode, T rspBody) {
        this.retCode = resultCode.getCode();
        this.retDesc = resultCode.getDesc();
        this.rspBody = rspBody;
    }

    public RspBody<T> setRetCode(String retCode) {
        this.retCode = retCode;
        return this;
    }

    public RspBody<T> setRetDesc(String retDesc) {
        this.retDesc = retDesc;
        return this;
    }

    public RspBody<T> setRspBody(T rspBody) {
        this.rspBody = rspBody;
        return this;
    }

    public String getRetCode() {
        return retCode;
    }


    public String getRetDesc() {
        return retDesc;
    }

    public T getRspBody() {
        return rspBody;
    }


}
